/***********************************************************************
 /////////////////////// SUBROUTINE POP3_LUMINOSITY \\\\\\\\\\\\\\\\\\\\\

     subroutine pop3_properties(mass, luminosity, lifetime)

     FINDS POPULATION III LIFETIME FROM TABLES

     written by: John Wise
     date:       12 September 2005
     modified1: John Wise (May, 2011) -- converted to C++

 INPUTS:
     mass - stellar mass [in solar masses]

 OUTPUTS:
     lifetime - [years]
***********************************************************************/

#include "ErrorExceptions.h"
#include "macros_and_parameters.h"
#include "typedefs.h"
#include "global_data.h"

float CalculatePopIIILifetime(float Mass)
{

  const float min_mass = 5.0;
  const float max_mass = 1000.0;
  const int nentries = 996;

  // Table for stellar lifetimes.  Mass = 5->1000 Msun.  dM = 1 Msun
  static float lifetimes[] =
    {6.190E+07,4.536E+07,3.366E+07,2.560E+07,2.022E+07,1.673E+07,
     1.443E+07,1.288E+07,1.181E+07,1.102E+07,1.040E+07,9.853E+06,
     9.357E+06,8.907E+06,8.494E+06,8.114E+06,7.762E+06,7.432E+06,
     7.122E+06,6.829E+06,6.549E+06,6.281E+06,6.024E+06,5.779E+06,
     5.548E+06,5.329E+06,5.124E+06,4.931E+06,4.752E+06,4.587E+06,
     4.434E+06,4.294E+06,4.168E+06,4.054E+06,3.953E+06,3.864E+06,
     3.788E+06,3.723E+06,3.668E+06,3.622E+06,3.585E+06,3.554E+06,
     3.529E+06,3.510E+06,3.496E+06,3.486E+06,3.480E+06,3.476E+06,
     3.474E+06,3.473E+06,3.473E+06,3.474E+06,3.474E+06,3.472E+06,
     3.469E+06,3.464E+06,3.456E+06,3.444E+06,3.431E+06,3.414E+06,
     3.396E+06,3.376E+06,3.354E+06,3.331E+06,3.306E+06,3.280E+06,
     3.254E+06,3.227E+06,3.199E+06,3.172E+06,3.144E+06,3.117E+06,
     3.090E+06,3.063E+06,3.037E+06,3.012E+06,2.988E+06,2.965E+06,
     2.943E+06,2.921E+06,2.901E+06,2.881E+06,2.863E+06,2.844E+06,
     2.827E+06,2.811E+06,2.795E+06,2.779E+06,2.765E+06,2.751E+06,
     2.737E+06,2.724E+06,2.712E+06,2.700E+06,2.688E+06,2.677E+06,
     2.667E+06,2.656E+06,2.647E+06,2.637E+06,2.628E+06,2.619E+06,
     2.611E+06,2.603E+06,2.595E+06,2.587E+06,2.580E+06,2.573E+06,
     2.566E+06,2.559E+06,2.552E+06,2.546E+06,2.539E+06,2.533E+06,
     2.527E+06,2.521E+06,2.515E+06,2.509E+06,2.503E+06,2.498E+06,
     2.492E+06,2.486E+06,2.481E+06,2.475E+06,2.470E+06,2.464E+06,
     2.459E+06,2.454E+06,2.448E+06,2.443E+06,2.438E+06,2.433E+06,
     2.428E+06,2.423E+06,2.418E+06,2.414E+06,2.409E+06,2.404E+06,
     2.400E+06,2.395E+06,2.390E+06,2.386E+06,2.381E+06,2.377E+06,
     2.373E+06,2.368E+06,2.364E+06,2.360E+06,2.356E+06,2.352E+06,
     2.348E+06,2.344E+06,2.340E+06,2.336E+06,2.332E+06,2.328E+06,
     2.324E+06,2.320E+06,2.317E+06,2.313E+06,2.309E+06,2.306E+06,
     2.302E+06,2.299E+06,2.295E+06,2.292E+06,2.288E+06,2.285E+06,
     2.282E+06,2.278E+06,2.275E+06,2.272E+06,2.269E+06,2.266E+06,
     2.262E+06,2.259E+06,2.256E+06,2.253E+06,2.250E+06,2.247E+06,
     2.244E+06,2.242E+06,2.239E+06,2.236E+06,2.233E+06,2.230E+06,
     2.228E+06,2.225E+06,2.222E+06,2.219E+06,2.217E+06,2.214E+06,
     2.212E+06,2.209E+06,2.207E+06,2.204E+06,2.202E+06,2.199E+06,
     2.197E+06,2.194E+06,2.192E+06,2.189E+06,2.187E+06,2.185E+06,
     2.182E+06,2.180E+06,2.178E+06,2.176E+06,2.174E+06,2.171E+06,
     2.169E+06,2.167E+06,2.165E+06,2.163E+06,2.161E+06,2.159E+06,
     2.157E+06,2.155E+06,2.153E+06,2.151E+06,2.149E+06,2.147E+06,
     2.145E+06,2.143E+06,2.141E+06,2.139E+06,2.137E+06,2.135E+06,
     2.134E+06,2.132E+06,2.130E+06,2.128E+06,2.127E+06,2.125E+06,
     2.123E+06,2.122E+06,2.120E+06,2.118E+06,2.117E+06,2.115E+06,
     2.113E+06,2.112E+06,2.110E+06,2.109E+06,2.107E+06,2.106E+06,
     2.104E+06,2.103E+06,2.101E+06,2.100E+06,2.098E+06,2.097E+06,
     2.095E+06,2.094E+06,2.093E+06,2.091E+06,2.090E+06,2.088E+06,
     2.087E+06,2.086E+06,2.085E+06,2.083E+06,2.082E+06,2.081E+06,
     2.079E+06,2.078E+06,2.077E+06,2.076E+06,2.075E+06,2.073E+06,
     2.072E+06,2.071E+06,2.070E+06,2.069E+06,2.068E+06,2.066E+06,
     2.065E+06,2.064E+06,2.063E+06,2.062E+06,2.061E+06,2.060E+06,
     2.059E+06,2.058E+06,2.057E+06,2.056E+06,2.055E+06,2.054E+06,
     2.053E+06,2.052E+06,2.051E+06,2.050E+06,2.049E+06,2.048E+06,
     2.047E+06,2.046E+06,2.045E+06,2.044E+06,2.043E+06,2.042E+06,
     2.041E+06,2.041E+06,2.040E+06,2.039E+06,2.038E+06,2.037E+06,
     2.036E+06,2.035E+06,2.035E+06,2.034E+06,2.033E+06,2.032E+06,
     2.031E+06,2.030E+06,2.030E+06,2.029E+06,2.028E+06,2.027E+06,
     2.027E+06,2.026E+06,2.025E+06,2.024E+06,2.023E+06,2.023E+06,
     2.022E+06,2.021E+06,2.020E+06,2.020E+06,2.019E+06,2.018E+06,
     2.018E+06,2.017E+06,2.016E+06,2.015E+06,2.015E+06,2.014E+06,
     2.013E+06,2.013E+06,2.012E+06,2.011E+06,2.011E+06,2.010E+06,
     2.009E+06,2.009E+06,2.008E+06,2.007E+06,2.006E+06,2.006E+06,
     2.005E+06,2.004E+06,2.004E+06,2.003E+06,2.002E+06,2.002E+06,
     2.001E+06,2.001E+06,2.000E+06,1.999E+06,1.999E+06,1.998E+06,
     1.997E+06,1.997E+06,1.996E+06,1.995E+06,1.995E+06,1.994E+06,
     1.993E+06,1.993E+06,1.992E+06,1.991E+06,1.991E+06,1.990E+06,
     1.989E+06,1.989E+06,1.988E+06,1.987E+06,1.987E+06,1.986E+06,
     1.986E+06,1.985E+06,1.984E+06,1.984E+06,1.983E+06,1.982E+06,
     1.982E+06,1.981E+06,1.980E+06,1.980E+06,1.979E+06,1.978E+06,
     1.977E+06,1.977E+06,1.976E+06,1.975E+06,1.975E+06,1.974E+06,
     1.973E+06,1.973E+06,1.972E+06,1.971E+06,1.970E+06,1.970E+06,
     1.969E+06,1.968E+06,1.968E+06,1.967E+06,1.966E+06,1.965E+06,
     1.965E+06,1.964E+06,1.963E+06,1.962E+06,1.962E+06,1.961E+06,
     1.960E+06,1.959E+06,1.959E+06,1.958E+06,1.957E+06,1.956E+06,
     1.956E+06,1.955E+06,1.954E+06,1.953E+06,1.953E+06,1.952E+06,
     1.951E+06,1.950E+06,1.950E+06,1.949E+06,1.948E+06,1.947E+06,
     1.946E+06,1.946E+06,1.945E+06,1.944E+06,1.943E+06,1.943E+06,
     1.942E+06,1.941E+06,1.940E+06,1.940E+06,1.939E+06,1.938E+06,
     1.937E+06,1.936E+06,1.936E+06,1.935E+06,1.934E+06,1.933E+06,
     1.933E+06,1.932E+06,1.931E+06,1.930E+06,1.929E+06,1.929E+06,
     1.928E+06,1.927E+06,1.926E+06,1.926E+06,1.925E+06,1.924E+06,
     1.923E+06,1.922E+06,1.922E+06,1.921E+06,1.920E+06,1.919E+06,
     1.919E+06,1.918E+06,1.917E+06,1.916E+06,1.916E+06,1.915E+06,
     1.914E+06,1.913E+06,1.913E+06,1.912E+06,1.911E+06,1.910E+06,
     1.910E+06,1.909E+06,1.908E+06,1.908E+06,1.907E+06,1.906E+06,
     1.905E+06,1.905E+06,1.904E+06,1.903E+06,1.903E+06,1.902E+06,
     1.901E+06,1.900E+06,1.900E+06,1.899E+06,1.898E+06,1.898E+06,
     1.897E+06,1.896E+06,1.896E+06,1.895E+06,1.894E+06,1.894E+06,
     1.893E+06,1.892E+06,1.892E+06,1.891E+06,1.890E+06,1.890E+06,
     1.889E+06,1.888E+06,1.888E+06,1.887E+06,1.886E+06,1.886E+06,
     1.885E+06,1.884E+06,1.884E+06,1.883E+06,1.883E+06,1.882E+06,
     1.881E+06,1.881E+06,1.880E+06,1.880E+06,1.879E+06,1.878E+06,
     1.878E+06,1.877E+06,1.877E+06,1.876E+06,1.875E+06,1.875E+06,
     1.874E+06,1.874E+06,1.873E+06,1.873E+06,1.872E+06,1.871E+06,
     1.871E+06,1.870E+06,1.870E+06,1.869E+06,1.869E+06,1.868E+06,
     1.868E+06,1.867E+06,1.867E+06,1.866E+06,1.865E+06,1.865E+06,
     1.864E+06,1.864E+06,1.863E+06,1.863E+06,1.862E+06,1.862E+06,
     1.861E+06,1.861E+06,1.860E+06,1.860E+06,1.859E+06,1.859E+06,
     1.858E+06,1.858E+06,1.857E+06,1.857E+06,1.856E+06,1.856E+06,
     1.855E+06,1.855E+06,1.854E+06,1.854E+06,1.853E+06,1.853E+06,
     1.853E+06,1.852E+06,1.852E+06,1.851E+06,1.851E+06,1.850E+06,
     1.850E+06,1.849E+06,1.849E+06,1.848E+06,1.848E+06,1.848E+06,
     1.847E+06,1.847E+06,1.846E+06,1.846E+06,1.845E+06,1.845E+06,
     1.845E+06,1.844E+06,1.844E+06,1.843E+06,1.843E+06,1.843E+06,
     1.842E+06,1.842E+06,1.841E+06,1.841E+06,1.841E+06,1.840E+06,
     1.840E+06,1.839E+06,1.839E+06,1.839E+06,1.838E+06,1.838E+06,
     1.837E+06,1.837E+06,1.837E+06,1.836E+06,1.836E+06,1.836E+06,
     1.835E+06,1.835E+06,1.834E+06,1.834E+06,1.834E+06,1.833E+06,
     1.833E+06,1.833E+06,1.832E+06,1.832E+06,1.832E+06,1.831E+06,
     1.831E+06,1.831E+06,1.830E+06,1.830E+06,1.830E+06,1.829E+06,
     1.829E+06,1.829E+06,1.828E+06,1.828E+06,1.828E+06,1.827E+06,
     1.827E+06,1.827E+06,1.826E+06,1.826E+06,1.826E+06,1.826E+06,
     1.825E+06,1.825E+06,1.825E+06,1.824E+06,1.824E+06,1.824E+06,
     1.824E+06,1.823E+06,1.823E+06,1.823E+06,1.822E+06,1.822E+06,
     1.822E+06,1.822E+06,1.821E+06,1.821E+06,1.821E+06,1.820E+06,
     1.820E+06,1.820E+06,1.820E+06,1.819E+06,1.819E+06,1.819E+06,
     1.819E+06,1.818E+06,1.818E+06,1.818E+06,1.818E+06,1.817E+06,
     1.817E+06,1.817E+06,1.817E+06,1.816E+06,1.816E+06,1.816E+06,
     1.816E+06,1.815E+06,1.815E+06,1.815E+06,1.815E+06,1.815E+06,
     1.814E+06,1.814E+06,1.814E+06,1.814E+06,1.813E+06,1.813E+06,
     1.813E+06,1.813E+06,1.813E+06,1.812E+06,1.812E+06,1.812E+06,
     1.812E+06,1.812E+06,1.811E+06,1.811E+06,1.811E+06,1.811E+06,
     1.811E+06,1.810E+06,1.810E+06,1.810E+06,1.810E+06,1.810E+06,
     1.810E+06,1.809E+06,1.809E+06,1.809E+06,1.809E+06,1.809E+06,
     1.808E+06,1.808E+06,1.808E+06,1.808E+06,1.808E+06,1.808E+06,
     1.807E+06,1.807E+06,1.807E+06,1.807E+06,1.807E+06,1.807E+06,
     1.807E+06,1.806E+06,1.806E+06,1.806E+06,1.806E+06,1.806E+06,
     1.806E+06,1.805E+06,1.805E+06,1.805E+06,1.805E+06,1.805E+06,
     1.805E+06,1.805E+06,1.805E+06,1.804E+06,1.804E+06,1.804E+06,
     1.804E+06,1.804E+06,1.804E+06,1.804E+06,1.803E+06,1.803E+06,
     1.803E+06,1.803E+06,1.803E+06,1.803E+06,1.803E+06,1.803E+06,
     1.803E+06,1.802E+06,1.802E+06,1.802E+06,1.802E+06,1.802E+06,
     1.802E+06,1.802E+06,1.802E+06,1.802E+06,1.801E+06,1.801E+06,
     1.801E+06,1.801E+06,1.801E+06,1.801E+06,1.801E+06,1.801E+06,
     1.801E+06,1.801E+06,1.801E+06,1.800E+06,1.800E+06,1.800E+06,
     1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.800E+06,
     1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,
     1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.797E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,1.798E+06,
     1.798E+06,1.798E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,
     1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.799E+06,1.800E+06,
     1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.800E+06,
     1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.800E+06,1.800E+06};

  float result;

  if (Mass < min_mass)
    result = lifetimes[0];
  else if (Mass > max_mass)
    result = lifetimes[nentries-1];
  else
    result = lifetimes[nint(Mass-min_mass)];
  
  return result;

}
